<!--    客户管理-客户详情---添加 回访记录组件  by jh   -->
<template>
    <div>
        <el-dialog title="添加回访记录" :visible="isAddReturnVisit"  @close="addReturnVisitFun" :close-on-click-modal="false" :show-close="false" :append-to-body="true">
            <el-form :model="form" label-width="80px">
                <el-row :gutter="10">
                    <el-col :span="12">
                        <el-form-item label="回访时间">
                            <el-date-picker
                                v-model="form.listGuestVisit[0].visitTime"
                                type="date"
                                placeholder="选择日期">
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="回访人" >
                            <!--<el-input v-model="form.listGuestVisit[0].visitUser" :maxlength="100"></el-input>-->
                            <el-select v-model="form.listGuestVisit[0].visitUser" filterable placeholder="请选择" class="ca-width-100">
                                <el-option
                                    v-for="(item,index) in userList"
                                    :key="index"
                                    :label="item.cnName"
                                    :value="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col>
                        <el-form-item label="内容记录">
                            <el-input type="textarea" placeholder="1000字" v-model="form.listGuestVisit[0].content" :maxlength="1000"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col>
                        <el-form-item label="待办事项">
                            <el-input type="textarea" placeholder="1000字" v-model="form.listGuestVisit[0].remark" :maxlength="1000"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col>
                        <csUploadButton
                        :isShowSelect="isShowSelect"
                        :fileType="fileType"
                        :businessId="form.visitId"
                        :getFileUploadedReturnData="getFileUploadedReturnData"
                        :deleteFileId="deleteFileId"
                        ></csUploadButton>
                    </el-col>
                </el-row>
            </el-form>
            <div  class="foot" style="text-align: center;">
                <el-button @click="addReturnVisitFun">取 消</el-button>
                <el-button type="primary" @click="onSubmit">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script type="text/ecmascript-6">
    import {api} from '../../../api';
    import {STATUS_HTTP_SUCCESS, apiHttp} from '__service/csHttp';
    export default {
        props: {
            isAddReturnVisit: {
                type: Boolean,
                required: true
            },
            addReturnVisitFun: {
                type: Function,
                required: true
            },
            userList: {
                type: Array,
                default: [],
            }
        },
        data() {
            return {
                isShowSearch: false,
                isShowSelect: false,
                isOnlyUpload: true,
                fileType: '10062',//文件上传的参数
                isAddReturnVisitShow: false,
                guestId: this.$route.params.eClient_guestId,
                form: {
                    'fileListId': [],
                    'guestId': '',
                    'listGuestVisit': [
                        {
                            'content': '', //内容记录
                            'guestId': '',
                            'id': '',
                            'remark': '',//待办事项
                            'visitTime': new Date(),//时间
                            'visitUser': this.$store.state.user.id //回访人===>默认为当前用户
                        }
                    ],
                    'visitId': ''
                }
            }
        },
        watch: {
        },
        mounted() {
        },
        methods: {
            //文件上传成功之后返回的数组
            getFileUploadedReturnData(arr) {
                let idArr = []
                arr.map((item)=>{
                    idArr.push(item.id)
                })
                this.form.fileListId = this.form.fileListId.concat(idArr)
            },
            deleteFileId(id) {
                this.form.fileListId.map((item,index)=> {
                    if (item === id) {
                        this.form.fileListId.splice(index,1)
                    }
                })
            },
            //添加 回访记录
            onSubmit() {
                if (this.form.listGuestVisit[0].visitUser.trim() === '') {
                    this.$message({
                        message: '请输入回访人',
                        type: 'error',
                        center: true
                    });
                    return;
                }
                let that = this
                let params = Object.assign({},this.form)
                //格式化时间
                params.listGuestVisit[0].visitTime = params.listGuestVisit[0].visitTime.getTime()
               // console.log(params.listGuestVisit[0].visitTime)
                //数据处理
                params.guestId = this.guestId
                params.listGuestVisit[0].guestId = this.guestId
                //console.log(params,"新建的参数")
                apiHttp(api.ADD_RETURN_RECORD,params).then(ret=> {
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        this.$message({
                            message: '添加成功',
                            type: 'success',
                            center: true
                        });
                        that.$emit('getReturnRecordList')
                        this.addReturnVisitFun()
                    }
                })
            }
        },
        components: {
           // 'csListEdit': require('__components/file-list/edit.vue'),//回访记录 列表与编辑
           // 'csUploadButton': require('__components/upload-btn'),//上传按钮
            'csUploadButton': require('__components/file-list/simple.vue'),//上传按钮
          },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.foot{
    margin-top: 30px;
}
</style>
